package com.dmai.capacity.platform.user.controller;

import com.dmai.capacity.platform.common.dto.PageResult;
import com.dmai.capacity.platform.common.dto.ResponseEntity;
import com.dmai.capacity.platform.user.pojo.request.LogCreateRequest;
import com.dmai.capacity.platform.user.service.ISysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 操作日志
 */
@RestController
public class SysLogController {

    @Autowired
    private ISysLogService logService;

    /**
     * 列表
     */
    @GetMapping("/logs")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = logService.pageAll(params);
        return pageResult;
    }

    /**
     * 写日志
     */
    @PostMapping("/logs")
    public ResponseEntity save(@RequestBody @Valid LogCreateRequest log) {
        logService.save(log);
        return ResponseEntity.succeed("操作成功");
    }

    /**
     * 批量写日志
     */
    @PostMapping("/batchLogs")
    public ResponseEntity saves(@RequestBody @Valid List<LogCreateRequest> logs) {
        logService.saves(logs);
        return ResponseEntity.succeed("操作成功");
    }
}
